home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / c_scripts / cgiscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-11  |  4.6 KB  |  156 lines

  1. /*
  2.    I got tired of looking at a ton of cgi hole scanners and none of 
  3.    them had everything included, so I made one for all the kode kiddies
  4.    out there. I ripped some of this code from 9x's shell script they
  5.    echo'ed to netcat, and some other guys code he ripped from someone else
  6.    (so I don't figure he deserves any credit, besides it was fucked up and
  7.    didn't work). 
  8.    
  9.    This will basicly asks a web server (Unix or NT) if they have these
  10.    programs open to the general public, and if they do, it tells you. I
  11.    could of made this exploit the holes as well, but I have to leave
  12.    something for you to do (well in the LoU released version it did
  13.    exploit them). Sometimes it will tell you that the files DO EXIST,
  14.    but you may not have access to them. By using another hole you may
  15.    be able to access them though. So if the scan returns that it found
  16.    something, don't instantly think you can exploit it.
  17.    
  18.    To complie:
  19.    luser$ gcc cgiscan.c -o cgiscan
  20.    To use:
  21.    luser$ ./cgiscan somedomain.com   (i.e. ./cgiscan antionline.com)
  22.    
  23.    coded by Bronc Buster of LoU - Jan 1999  
  24. */
  25.  
  26. #include <sys/types.h>
  27. #include <netinet/in.h>
  28. #include <string.h>
  29. #include <netdb.h>
  30. #include <ctype.h>
  31. #include <arpa/nameser.h>
  32. #include <strings.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <unistd.h>
  36. #include <sys/socket.h>
  37. #define MAX_SIZE 21  /* make this the size of temp[] if you change it */
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41.  int s;
  42.  struct in_addr addr;
  43.  struct sockaddr_in victem;
  44.  struct hostent *he;
  45.  char foundmsg[] = "404";
  46.  char *cgistr;
  47.  char buffer[1024];
  48.  char cgibuff[1024]; 
  49.  int num,i=0;
  50.  char *temp[22];    
  51.  char *name[22]; 
  52.  
  53.  temp[1] = "GET /cgi-bin/phf HTTP/1.0\n\n";
  54.  temp[2] = "GET /cgi-bin/Count.cgi HTTP/1.0\n\n";
  55.  temp[3] = "GET /cgi-bin/test-cgi HTTP/1.0\n\n";
  56.  temp[4] = "GET /cgi-bin/php.cgi HTTP/1.0\n\n";
  57.  temp[5] = "GET /cgi-bin/handler HTTP/1.0\n\n";
  58.  temp[6] = "GET /cgi-bin/webgais HTTP/1.0\n\n";
  59.  temp[7] = "GET /cgi-bin/websendmail HTTP/1.0\n\n";
  60.  temp[8] = "GET /cgi-bin/webdist.cgi HTTP/1.0\n\n";
  61.  temp[9] = "GET /cgi-bin/faxsurvey HTTP/1.0\n\n";
  62.  temp[10] = "GET /cgi-bin/htmlscript HTTP/1.0\n\n";
  63.  temp[11] = "GET /cgi-bin/pfdispaly.cgi HTTP/1.0\n\n";
  64.  temp[12] = "GET /cgi-bin/perl.exe HTTP/1.0\n\n";
  65.  temp[13] = "GET /cgi-bin/wwwboard.pl HTTP/1.0\n\n";
  66.  temp[14] = "GET /cgi-bin/www-sql HTTP/1.0\n\n";
  67.  temp[15] = "GET /_vti_pvt/service.pwd HTTP/1.0\n\n";
  68.  temp[16] = "GET /_vti_pvt/users.pwd HTTP/1.0\n\n";
  69.  temp[17] = "GET /cgi-bin/aglimpse HTTP/1.0\n\n";
  70.  temp[18] = "GET /cgi-bin/man.sh HTTP/1.0\n\n";
  71.  temp[19] = "GET /cgi-bin/view-source HTTP/1.0\n\n";
  72.  temp[20] = "GET /cgi-bin/campas HTTP/1.0\n\n";
  73.  temp[21] = "GET /cgi-bin/nph-test-cgi HTTP/1.0\n\n";
  74.  
  75.  name[1] = "phf";
  76.  name[2] = "Count.cgi";
  77.  name[3] = "test-cgi";
  78.  name[4] = "php.cgi";
  79.  name[5] = "handler";
  80.  name[6] = "webgais";
  81.  name[7] = "websendmail";
  82.  name[8] = "webdist.cgi";
  83.  name[9] = "faxsurvey";
  84.  name[10] = "htmlscript";
  85.  name[11] = "pfdisplay";
  86.  name[12] = "perl.exe";
  87.  name[13] = "wwwboard.pl";
  88.  name[14] = "www-sql";
  89.  name[15] = "service.pwd";
  90.  name[16] = "users.pwd";
  91.  name[17] = "aglimpse";
  92.  name[18] = "man.sh";
  93.  name[19] = "view-source";
  94.  name[20] = "campas";
  95.  name[21] = "nph-test-cgi";
  96.  
  97.  if (argc!=2)
  98.    {
  99.    exit(printf("\nUsage : %s domain.com\n",argv[0])); 
  100.    }
  101.  if ((he=gethostbyname(argv[1])) == NULL)
  102.    {
  103.    exit(printf("Error getting hostname"));
  104.    }
  105.  
  106. printf("New web server hole and info scanner for elite kode kiddies\n");
  107. printf("coded by Bronc Buster of LoU - Jan 1999\n");
  108.  
  109. s=socket(AF_INET, SOCK_STREAM, 0);
  110.  if(s<0) exit(printf("Socket error"));
  111. bcopy(he->h_addr, (char *)&victem.sin_addr, he->h_length);
  112. victem.sin_family=AF_INET;
  113. victem.sin_port=htons(80);
  114.  
  115. if (connect(s, (struct sockaddr*)&victem, sizeof(victem))<0)
  116.   {
  117.   exit(printf("Connect error"));
  118.   }
  119. printf("\nGetting HTTP version\n\n");
  120. send(s, "HEAD / HTTP/1.0\n\n",17,0);
  121. recv(s, buffer, sizeof(buffer),0);
  122. printf("Version:\n%s",buffer);
  123.    //send(s, "GET / HTTP/1.0\n\n",16,0);
  124.    //recv(s,buffer,sizeof(buffer),0);
  125.    //printf("
  126. close(s); 
  127.    
  128. while(i++ < MAX_SIZE)   
  129.   {
  130.   s=socket(AF_INET, SOCK_STREAM, 0);
  131.   bcopy(he->h_addr, (char *)&victem.sin_addr, he->h_length);
  132.   victem.sin_family=AF_INET;
  133.   victem.sin_port=htons(80);
  134.   if (connect(s, (struct sockaddr*)&victem, sizeof(victem))<0)
  135.     {
  136.     exit(printf("Connect error"));
  137.     }
  138.   printf("Searching for %s : ",name[i]);
  139.   for(num=0; num<1024; num++)
  140.       {
  141.       cgibuff[num] = '\0';
  142.       } 
  143.   
  144.    send(s, temp[i],strlen(temp[i]),0);
  145.    recv(s, cgibuff, sizeof(cgibuff),0);
  146.    cgistr = strstr(cgibuff,foundmsg);
  147.    if(cgistr == NULL)
  148.        printf(" * * Found * * \n");
  149.    else
  150.        printf(". . Not Found . .\n");
  151.       
  152.    close(s);
  153.    }
  154. return 0;
  155.  }
  156.